package com.wangyg.juc.BreadMaker;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by wangyg6 on 2018/7/10.
 */
public class Maker implements Runnable {
	BlockingQueue<Integer> bq;
	private static AtomicInteger integer = new AtomicInteger();

	public Maker setBq(BlockingQueue<Integer> bq) {
		this.bq = bq;
		return this;
	}

	@Override
	public void run() {
		while (true) {
			String name = Thread.currentThread().getName();
			int i = integer.incrementAndGet();
			System.out.println(name + "：make了第" + i + "个面包");
			try {
				Thread.sleep((long) (Math.random() * 10));
				bq.put(i);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
